<?php 


namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
use app\admin\controller\Admin;

/**
* 
*/
class Safe extends Admin
{
    /**
     * [index 加载首页]
     */
    public function index()
    {
        $list = db('_safety_workable_record')
            ->select();
        //var_dump($safe);die;
        return view('admin@safe/index',[
            'safe' => $list
        ]);
    }

<<<<<<< HEAD

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        // echo 'read'; die;
        // 是否为Ajax请求
        if (!Request::instance()->isAjax()) {
            $this->error('你是不是迷路了?', '/');
        }

        // 查询指定用户信息 显示查询
        $row = db('_safety_workable_record')->field(true)->find($id);

        if ($row === null) {
            $info['status'] = false;
            $info['title'] = '查无数据';
            $info['datas'] = '查无数据,请您重试!';
        } else {
            $info['status'] = true;
            $info['title'] = $row['project_name'];
            $info['data'] = $row['safety_job_content'];
        }
        return json($info);
    }



    /**Ajax 删除
     * [delete 执行安全计划删除]
     */
    public function delete($id)
    {
        $result = db('_safety_workable_record')->delete($id);
        // var_dump($result); exit;
        if ($result > 0) {
            $info['status'] = true;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的安全管理删除成功!';
        } else {
            $info['status'] = false;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的安全管理删除失败!';
        }

        return json($info);
    }











=======
>>>>>>> a40bd7c37eef93aca4b7ae3126fd10da65b4232b
    /**
     * [addsafe 加载添加安全计划页面]
     */
    public function addsafe()
    {
        
        //var_dump($res);die;
        return view('admin@safe/addsafe');
    }

    /**
     * [doaddsafe 执行添加安全计划]
     */
    public function doaddsafe()
    {
        $res = input('param.');
        //var_dump($res);die;
        $res['date'] = date("Y-m-d H:i:s",time());
        //var_dump($res);die;
        $result = db('_safety_workable_record')
                  ->insert($res);
        //var_dump($result);
        //var_dump($user->id);
        if ($result > 0) {
            return $this->success('添加成功!', url('admin/safe/index'));
        } else {
            return $this->error('添加失败!');
        }

    }

    /**
     * [edit 加载安全计划编辑页面]
     */
    public function edit()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];
        $res = db('_safety_workable_record')->field(['id','project_name','safety_job_content','safety_job_requirement','safety_job_logging','status'])->find($id);
        //var_dump($res);die;
        return view('admin@safe/edit',[
            'res' => $res
        ]);
    }

    /**
     * [doedit 执行安全计划编辑]
     */
    public function doedit()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];

        $result = db('_safety_workable_record')->where('id='.$id)->update($p);
        //var_dump($res);die;
        if ($result > 0) {
            return $this->success('编辑成功!', url('admin/safe/index'));
        } else {
            return $this->error('编辑失败!');
        }
    }

<<<<<<< HEAD
    


=======
    /**Ajax 删除
     * [delete 执行安全计划删除]
     */
    public function delete($id)
    {
        $result = db('_safety_workable_record')->delete($id);
        // var_dump($result); exit;
        if ($result > 0) {
            $info['status'] = true;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的安全管理删除成功!';
        } else {
            $info['status'] = false;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的安全管理删除失败!';
        }

        return json($info);
    }

    public function dodel()
    {
        $p = input('param.');
        //var_dump($p);exit;

        //把用户角色表中相关的也删除
        if(db('_safety_workable_record')->where('id',$p['id'])->delete()){
            $this->success("删除成功！",url('admin/safe/index'));
        }else{
            $this->error("删除失败");
        }

    }
>>>>>>> a40bd7c37eef93aca4b7ae3126fd10da65b4232b


    /**
     * [fee 加载费用总览页面]
     */
    public function fee()
    {
        $list = db('_safety_fee')
            ->select();
        //var_dump($list);die;
        return view('admin@safe/fee',[
            'list' => $list
        ]);
    }
    /**
     * [addfeehtml 加载添加费用总览页面]
     */
    public function addfeehtml()
    {
        //$list = db('_safety_workable_record')
        //    ->field(['id','project_name'])
        //    ->select();
        //var_dump($list);die;
        return view('admin@safe/addfee');
    }

    /**
     * [addfee 执行添加费用总览]
     */
    public function addfee()
    {
        $res = input('param.');
        //var_dump($res);die;
        $res['month'] = date("Y-m-d H:i:s",time());
        //var_dump($res);die;
        $result = db('_safety_fee')
                  ->insert($res);
        //var_dump($result);
        //var_dump($user->id);
        if ($result > 0) {
            return $this->success('添加成功!', url('admin/safe/fee'));
        } else {
            return $this->error('添加失败!');
        }
    }




    /**
     * [editfeehtml 修改费用总览]
     */
    public function editfeehtml()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];
        $res = db('_safety_fee')->field(['id','project_name','environmental_expenditure','civilized_costs','safety_costs','temporary_facility_fee','status'])->find($id);
        //var_dump($res);die;
        return view('admin@safe/editfee',[
            'res' => $res
        ]);
    }

    /**
     * [editfee 执行费用总览]
     */
    public function editfee()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];

        $result = db('_safety_fee')->where('id='.$id)->update($p);
        //var_dump($res);die;
        if ($result > 0) {
            return $this->success('编辑成功!', url('admin/safe/fee'));
        } else {
            return $this->error('编辑失败!');
        }
    }

    /**
     * [feedel 删除费用总览]
     */
    public function feedel()
    {
        $p = input('param.');
        //var_dump($p);exit;

        
        if(db('_safety_fee')->where('id',$p['id'])->delete()){
            $this->success("删除成功！",url('admin/safe/fee'));
        }else{
            $this->error("删除失败");
        }
    }








    /**
     * [plan 加载落实情况页面]
     */
    public function plan()
    {
        $list = db('_safety_plan')
            ->select();
        //var_dump($list);die;
        return view('admin@safe/plan',[
            'list' => $list
        ]);
    }

    /**
     * [delplan 执行删除落实情况]
     */
    public function delplan()
    {
        $p = input('param.');
        //var_dump($p);exit;

        //把用户角色表中相关的也删除
        if(db('_safety_plan')->where('id',$p['id'])->delete()){
            $this->success("删除成功！",url('admin/safe/plan'));
        }else{
            $this->error("删除失败");
        }
    }


}

 ?>